
load('summary_data/fig5.rda')

x_l = c('[0,90)','[90,95)','[95,99)','[99,99.5)','[99.5,99.9)','[99.9,)')

out = rbindlist(list(d12,d20,r12,r20)) %>%
  mutate(class = factor(class, levels = unique(class)[c(3:4,1:2)])) %>%
  mutate(lty = if_else(str_starts(class, 'R'), 'solid','dashed'),
         a= if_else(str_starts(class, 'R'), 1, 1)) %>%
  ggplot(aes(x = nat_quant_col, y = sq, fill = class, group = class, color = class, linetype = lty, alpha = a, shape = class)) +
  geom_point(aes(alpha=a)) +
  geom_line() +
  theme_light() +
  scale_x_discrete(labels = x_l) +
  scale_linetype_identity() +
  scale_alpha_identity() +
  scale_color_manual(values = c("deepskyblue", "darkslateblue", "brown1", "darkred")[c(3:4, 1:2)]) +
  scale_y_continuous(
    labels = scales::label_percent(),
    limits = c(0, .55),
    breaks = c(.1, .2, .3, .4, .5)
  ) +
  labs(
    x = element_blank(),
    y = '% Donor Retention',
    fill = element_blank(),
    shape = element_blank()
  ) +
  scale_shape_manual(values = c(17, 19, 2, 1)) +
  guides(
    alpha = 'none',
    fill = 'none',
    color = guide_legend(
      nrow = 2,
      byrow = TRUE,
      title = element_blank()
    )
  ) +
  theme(
    legend.position = c(.7, .125),
    axis.text.x = element_text(
      angle = 25,
      vjust = .85,
      hjust = 0.5,
      size = 7
    ),
    legend.text = element_text(size = 7),
    strip.background = element_rect(fill = 'white'),
    strip.text.x = element_text(
      face = 'bold',
      size = 10,
      color = 'black'
    ),
    legend.spacing.y = unit(0, 'cm'),
    text = element_text(face = 'bold')
  )

ggsave(filename = 'figures/fig5.pdf', plot = out, width = 6, height = 4, units = 'in')
